<#compress>
<!DOCTYPE html>
<html>
	<head>
		<title>角色成员管理</title>
		<meta name="keywords" content="keyword1,keyword2,keyword3">
		<meta name="description" content="this is my page">
		<meta name="content-type" content="text/html; charset=UTF-8">
		<base href="${webroot}">
		<#include "../../template/easyui.ftl" parse="true" encoding="UTF-8">
	</head>
	<body>
		<div class="easyui-layout" data-options="fit:true,border:false" >
			<div data-options="region:'west',split:true,border:false" style="width:50%;">
				<table class="easyui-datagrid" noparse title="" id="usergrid"
				  		 data-options="
				  		 	pageSize:20,
				  		 	striped:true,
				  		 	border:false,
				  		 	url: 'role/role_userchoose_list.grid',
				  		 	method: 'get',
				  		 	rownumbers: true,
				  		 	pagination: true,
				  		 	fit: true,
				  		 	toolbar: '#tb',
				  		 	onDblClickRow: module.onDblClickRow
				  		 ">
					<thead >
						<tr>
							<th data-options="field:'id',width:50,checkbox:true">ID</th>
							<th data-options="field:'u_alias',width:180">用户名</th>
							<th data-options="field:'u_account',width:100">账号</th>
						</tr>
					</thead>
				</table>
				<div id="tb" style="padding:5px;height:auto">
					<div style="margin-bottom:5px">
						用户名:
						<input id="username" class="easyui-textbox" data-options="prompt:'输入关键字进行查询'" style="width:140px;">
						<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onclick="chGridQuery('username','usergrid');">查询</a>
						<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-useradd" onclick="addMember();">添加</a>
						<br>
						
					</div>
				</div>
            </div>
			<div data-options="region:'center',border:false" >
				<table class="easyui-datagrid" title="" id="usergrid1" noparse
				  		 data-options="
				  		 	pageSize:20,
				  		 	striped:true,
				  		 	border:false,
				  		 	<#--url: 'role/user_bind_list.grid',-->
				  		 	method: 'get',
				  		 	rownumbers: true,
				  		 	pagination: true,
				  		 	fit: true,
				  		 	toolbar: '#tb1',
				  		 	onDblClickRow: module.onDblClickRow
				  		 ">
					<thead >
						<tr>
							<th data-options="field:'id',width:50,checkbox:true">ID</th>
							<th data-options="field:'u_alias',width:180">用户名</th>
							<th data-options="field:'u_account',width:100">账号</th>
						</tr>
					</thead>
				</table>
				<div id="tb1" style="padding:5px;height:auto">
					<div style="margin-bottom:5px">
						用户名:
						<input id="username1" class="easyui-textbox" data-options="prompt:'输入关键字进行查询'" style="width:140px;">
						<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onclick="chGridQuery('username1','usergrid1');">查询</a>
						<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-userdelete" onclick="delMember();">删除</a>
						<br>
						
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
	var currentRoleId=null;
	function chGridQuery(textid,gridid){
		var username = $('#'+textid).textbox('getValue');
		var filters = [];
		filters.push(add_condition("and", "包含", "", "u_alias", username, "", "string"));
		fun_query(gridid, filters);
		filters = null;
	}
	function loadBindUser(rolid){
		currentRoleId=rolid;
		$('#usergrid1').datagrid({
			url:'role/user_bind_list.grid?roleid='+rolid
		});
	}
	function addMember(){
		var rows = $('#usergrid').datagrid('getChecked'); 
		if(rows.length==0){
			$.messager.alert('警告','请选择用户！','warning');
			return;
		}
		
		$.messager.confirm('确认','您确认要添加所选记录吗？',function(r){    
		    if (r){    
		    	var ids =new Array();
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i].id); 
				}
				$.ajax({
					type : "post",
					url : "role/addRoleMember.do",
					data:{roleId:currentRoleId,userids:ids.join()},
					dataType:"json",
					success : function(data) {
						if(data.status){
							$.messager.alert('提示',data.msg,'info');
							$('#usergrid1').datagrid('reload');
							$('#usergrid').datagrid('unselectAll');
						}else{
							$.messager.alert('提示',data.msg,'error');
						}
					},
			    	error : function() {
			    		$.messager.alert('error','网络超时，请稍后再试！');
			    	}
				});
		    }    
		});
	}
	
	function delMember(){
		var rows = $('#usergrid1').datagrid('getChecked'); 
		if(rows.length==0){
			$.messager.alert('警告','请选择用户！','warning');
			return;
		} 
		$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
		    if (r){    
		       //start
		    	var ids =new Array();
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i].id); 
				}
				$.ajax({
					type : "post",
					url : "role/delRoleMember.do",
					data:{ids:ids.join()},
					dataType:"json",
					success : function(data) {
						if(data.status){
							$.messager.alert('提示',data.msg,'info');
							$('#usergrid1').datagrid('reload');
							$('#usergrid1').datagrid('unselectAll');
						}else{
							$.messager.alert('提示',data.msg,'error');
						}
					},
			    	error : function() {
			    		$.messager.alert('error','网络超时，请稍后再试！');
			    	}
				});
				//end
		    }    
		});
		
	}
	</script>
</html>
</#compress>